#ifndef BOARDLOGGER_H
#define BOARDLOGGER_H

#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QMutex>
#include <QTextStream>

class BoardLogger
{
public:
    static BoardLogger& instance();

    // 记录串口数据
    void logSerialData(const QString& portName, const QByteArray& data, bool isReceived = true);

    // 记录格式化消息
    void logMessage(const QString& message);

    // 记录十六进制数据
    void logHexData(const QString& portName, const QByteArray& data, bool isReceived = true);

private:
    BoardLogger() = default;
    ~BoardLogger() = default;
    BoardLogger(const BoardLogger&) = delete;
    BoardLogger& operator=(const BoardLogger&) = delete;

    void writeToLog(const QString& logContent);
    QString getCurrentLogPath();
    void ensureLogDirectory(const QString& logPath);

    QMutex m_mutex;
    QString m_currentLogPath;
    static BoardLogger* m_instance;
};

#endif  // BOARDLOGGER_H